package com.eunion.web.common.controller;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

/**
 * Created by xiaoji on 2015/9/24. 图片上传DEMO
 */
@Controller
@RequestMapping(value = "/file")
public class FileUploaderController {
	/**
	 * 上传DEMO
	 */
	@RequestMapping(value = "/upload", method = { RequestMethod.POST })
	public void images(ModelMap modelMap, HttpServletRequest request, @RequestParam("file") MultipartFile file) {

		String path = "D:\\upload\\" + file.getOriginalFilename();
		File targetFile = new File(path);
		try {
			file.transferTo(targetFile);
		} catch (IOException e) {
			e.printStackTrace();
		}

		// modelMap.addAllAttributes(SYS.SUCCESS.Msg);
	}

	@RequestMapping(value = "/toupload", method = { RequestMethod.GET })
	public String to() {
		return "hello/upload";
	}

}
